#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 20;

int n, T, m;
bool ban[N][N];
ll f[N][1 << 11];
bool ok[1 << 11];

int main() {
#ifdef YJR_2333_TEST
	freopen("1.in", "r", stdin);
#endif
	n = in, T = in, m = in;
	rep(i, 1, m) {
		int u = in - 1, v = in - 1;
		ban[u][v] = true;
	} int U = 1 << n;
	rep(s, 0, U - 1) {
		ok[s] = true;
		rep(j, 0, n - 1) if(s >> j & 1) rep(k, 0, n - 1) if(s >> k & 1)
											ok[s] &= !ban[j][k];
	}
	f[0][0] = 1;
	rep(i, 1, T) rep(s, 0, U - 2) if(f[i - 1][s]) {
		int x = -1;
		rep(j, 0, n - 1) if(~s >> j & 1) x = j;
		for(int ts = (U - 1) ^ s, t = ts; ; t = (t - 1) & ts) {
			if(ok[t] && t >> x & 1) f[i][t | s] += f[i - 1][s];
			if(t == 0) break;
		}
	} cout << f[T][U - 1] << endl;
	return 0;
}
